package com.ruoyi.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;

/**
 * 6.2 删除流程定义信息
 */
public class DeleteProcessDefinition {
    public static void main(String[] args) {
       delete("60001");
    }

    ///删除流程，返回错误码
    public static String delete(String id)
    {
        System.out.println("删除流程id="+id);
        try {
            //1.获取ProcessEngine对象
            ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
            //2.创建repositoryService对象
            RepositoryService repositoryService = processEngine.getRepositoryService();
            //3.执行删除流程
            repositoryService.deleteDeployment(id);
        }
        catch (Exception e)
        {
            if(e.getMessage().contains("Could not find a deployment with id"))
            {
                System.out.println("刪除的流程不存在，id="+id);
                return "流程id不存在";
            }
        }
        return "";
    }
}
